package com.ruoyi.web.controller.books;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.books.domain.BooksCategory;
import com.ruoyi.books.service.IBooksCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 非遗分类汇总Controller
 *
 * @author FeiYiLand
 * @date 2024-03-25
 */
@Anonymous
@RestController
@RequestMapping("/books/category")
public class BooksCategoryController extends BaseController
{
    @Autowired
    private IBooksCategoryService booksCategoryService;

    /**
     * 查询非遗分类汇总列表
     */
//    @PreAuthorize("@ss.hasPermi('books:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(BooksCategory booksCategory)
    {
        startPage();
        List<BooksCategory> list = booksCategoryService.selectBooksCategoryList(booksCategory);
        return getDataTable(list);
    }

    /**
     * 导出非遗分类汇总列表
     */
//    @PreAuthorize("@ss.hasPermi('books:category:export')")
    @Log(title = "非遗分类汇总", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BooksCategory booksCategory)
    {
        List<BooksCategory> list = booksCategoryService.selectBooksCategoryList(booksCategory);
        ExcelUtil<BooksCategory> util = new ExcelUtil<BooksCategory>(BooksCategory.class);
        util.exportExcel(response, list, "非遗分类汇总数据");
    }

    /**
     * 获取非遗分类汇总详细信息
     */
//    @PreAuthorize("@ss.hasPermi('books:category:query')")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return success(booksCategoryService.selectBooksCategoryByCategoryId(categoryId));
    }

    /**
     * 新增非遗分类汇总
     */
//    @PreAuthorize("@ss.hasPermi('books:category:add')")
    @Log(title = "非遗分类汇总", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BooksCategory booksCategory)
    {
        return toAjax(booksCategoryService.insertBooksCategory(booksCategory));
    }

    /**
     * 修改非遗分类汇总
     */
//    @PreAuthorize("@ss.hasPermi('books:category:edit')")
    @Log(title = "非遗分类汇总", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BooksCategory booksCategory)
    {
        return toAjax(booksCategoryService.updateBooksCategory(booksCategory));
    }

    /**
     * 删除非遗分类汇总
     */
//    @PreAuthorize("@ss.hasPermi('books:category:remove')")
    @Log(title = "非遗分类汇总", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds)
    {
        return toAjax(booksCategoryService.deleteBooksCategoryByCategoryIds(categoryIds));
    }
}
